package com.nescafe.nescafepromo.servlet;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nescafe.nescafepromo.controller.AdminController;
import com.nescafe.nescafepromo.model.NPRequest;
import com.nescafe.nescafepromo.model.NPResponse;

public class AdminServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		NPRequest request = new NPRequest(req);
		AdminController ctr = new AdminController();
		NPResponse response = ctr.process(request);

		resp.setContentType("text/html");
		resp.setCharacterEncoding("UTF-8");
		Writer writer = null;

		try {
			writer = resp.getWriter();
			writer.write(response.getMessage());
		} finally {
			writer.close();
		}

	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

	}

}
